﻿--HEADER Alter FullText Index on UDS.DiaryEntry, SecurityView; DIayr Entry Changes
--SKIPTRANSACTION
IF NOT EXISTS (SELECT 'Name' FROM INFORMATION_SCHEMA.COLUMNS 
			   WHERE TABLE_NAME = 'DiaryEntry' 
			   AND TABLE_SCHEMA = 'UDS'
		       AND  COLUMN_NAME = 'Name')
BEGIN		
	ALTER TABLE [UDS].[DiaryEntry]
	ADD Name nvarchar(max) null
END 

GO	

UPDATE DiaryEntry SET Name = Answer.Value
from [UDS].DiaryEntry
join UDS.Answer on DiaryEntry.Id = Answer.ID

drop FULLTEXT INDEX ON [UDS].[DiaryEntry]

GO

CREATE FULLTEXT INDEX ON [UDS].[DiaryEntry]
    ([Name], [Text] LANGUAGE 1033)
    KEY INDEX [PK_DiaryEntry]
    ON [IIP]
	WITH STOPLIST= OFF;

